package com.zn.product.service;

import com.zn.product.dao.ProductDao;
import com.zn.product.dao.ShoppingCar;
import com.zn.product.model.Product;

import java.util.List;

public class ProductService {
    public List<Product> getProductDao() {
        return null;
    }

    List<Product> list = getProductList();

    public List<Product> getProductList() {
        return null;
    }
//    return list;
    //根据商品编号来获取商品信息
    public Product getProductById(String id) {
        ProductDao dao = new ProductDao();
            Product product = dao.getProductById(id);
            return  product;

    }

    public boolean addCar(String customerId, String productId, String number) {
        ProductDao dao = new ProductDao();
        int num = dao.isExist(customerId,productId);
        int result = 0;
        if (num > 0){
            result = dao.updateCar(customerId,productId,String.valueOf(num+1));
        }else {
            result = dao.addCar(customerId, productId, number);
        }
//        int result = dao.addCar(customerId, productId, number);
        return result == 1;
    }

    public List<ShoppingCar> getProductByCustomerId(String customerId) {
        ProductDao dao = new ProductDao();
        List<ShoppingCar> list = dao.getShoppingCarInfo(customerId);
        return list;
    }
    public List<ShoppingCar> getShoppingCarInfo(String customerId) {
        ProductDao dao = new ProductDao();
        List<ShoppingCar> list = dao.getShoppingCarInfo(customerId);
        return list;
    }
public  boolean addOrder(String phone,String price,List<ShoppingCar> list) {
        ProductDao dao = new ProductDao();
        int num = dao.addOrder(phone, price,list);
        return  num > 0;
}


}
